<template>
  <el-dialog v-loading="loading" :append-to-body="true" :close-on-click-modal="false" :visible.sync="visable" title="教师发表审核" width="1200px" top="3vh" @close="closeDlg">
    <el-row>
      <el-col :span="17">
        <table class="billinfo-table" width="100%">
          <tr>
            <td colspan="2"><div class="bill-item"><label>申请标题</label><p>{{ entity.applyName }}</p></div></td>
          </tr>
          <tr>
            <td width="50%"><div class="bill-item"><label>申请人</label><p>{{ entity.applicantName }}</p></div></td>
            <td width="50%"><div class="bill-item"><label>申请时间</label><p>{{ entity.applyTime | parseTime("{y}-{m}-{d}") }}</p></div></td>
          </tr>
          <tr>
            <td><div class="bill-item"><label>所属部门</label><p>{{ entity.deptName }}</p></div></td>
            <td><div class="bill-item"><label>教师发表名称</label><p>{{ entity.name }}</p></div></td>
          </tr>
          <tr>
            <td><div class="bill-item"><label>成果形式</label><p>{{ entity.typeName }}</p></div></td>
            <td><div class="bill-item"><label>承担角色</label><p>{{ entity.role }}</p></div></td>
          </tr>
          <tr>
            <td><div class="bill-item"><label>第一作者</label><p>{{ entity.firstAuthor }}</p></div></td>
            <td><div class="bill-item"><label>刊物名称</label><p>{{ entity.publishName }}</p></div></td>
          </tr>
          <tr colspan="2">
            <td><div class="bill-item"> <label style="width:150px;">第一作者所属单位</label><p>{{ entity.firsAuthorOrg }}</p></div></td>
          </tr>
          <tr>
            <td><div class="bill-item"><label>刊物级别</label><p>{{ entity.publishLevelName }}</p></div></td>
            <td><div class="bill-item"><label>期刊号/书号</label><p>{{ entity.publishNo }}</p></div></td>
          </tr>
          <tr>
            <td><div class="bill-item"><label>出版单位</label><p>{{ entity.press }}</p></div></td>
            <td><div class="bill-item"><label>发表日期</label><p>{{ entity.pressDate | parseTime("{y}-{m}-{d}") }}</p></div></td>
          </tr>
          <tr>
            <td colspan="2"><div class="bill-item"><label>成果描述"</label><p>{{ entity.content }}</p></div></td>
          </tr>
          <tr>
            <td colspan="2">
              <div class="bill-item"><label>附件</label>
                <p>
                  <a v-for="(po) in appendFileList" :key="po.url" :download="po.name" :href="po.url" style="margin-bottom:8px;display: block" target="_blank">{{ po.name }}</a>
                </p>
              </div>
            </td>
          </tr>
        </table>
      </el-col>
      <el-col :span="7">
        <div class="right-approve-panel">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <b style="color:#ffcc66">审批申请</b>
            </div>
            <div>
              <el-form ref="pform" v-enter2tab="true" :model="form" :rules="rules" size="small">
                <el-form-item label="审核意见" prop="comment">
                  <el-input v-model="form.comment" type="textarea" maxlength="300" autocomplete="off" :rows="5" placeholder="请输入" />
                </el-form-item>
              </el-form>
            </div>
            <div class="approve-footer">
              <el-button type="text" @click="closeDlg">取消</el-button>
              <el-button type="primary" @click="doSubmit">确认</el-button>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import request from '@/utils/request'
export default {
  name: 'PublishAuditForm',
  data() {
    return {
      loading: false,
      visable: false,
      form: {
        taskId: '',
        procInstId: '',
        entityId: '',
        comment: '',
        passed: true
      },
      rules: {
        comment: [
          { required: true, message: '必填', trigger: 'blur' }
        ]
      },
      entity: {
        id: null,
        applicantId: '',
        applicantName: '',
        applyName: '',
        applyTime: '',
        typeName: '',
        content: '',
        role: '',
        firstAuthor: '',
        firsAuthorOrg: '',
        Name: '',
        publishLevelName: '',
        publishNo: '',
        press: '',
        pressDate: '',
        appendFiles: null
      },
      appendFileList: []
    }
  },
  methods: {
    cancel() {
      this.closeDlg()
    },
    show(task) {
      this.form.taskId = task.taskId
      this.form.procInstId = task.procInstId
      request({ url: '/edu/publish/' + task.businessKey, method: 'get' }).then(data => {
        this.entity = data
        this.form.entityId = data.id
        // appenfile
        if (this.entity.appendFiles) {
          this.appendFileList = JSON.parse(this.entity.appendFiles)
        }
        this.visable = true
      }).catch(err => {
        this.$message.error(err.message)
      })
    },
    doSubmit() {
      this.$refs['pform'].validate((valid) => {
        if (valid) {
          this.loading = true
          this.doApprove()
        }
      })
    },
    doApprove() {
      request({ url: '/edu/publish/auditApply', method: 'post', data: this.form }).then(res => {
        this.closeDlg()
        this.$notify({
          title: '提交审核成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.getList()
      }).catch(err => {
        this.loading = false
        this.$message.error('提交审核错误！' + err.message)
      })
    },
    closeDlg() {
      this.form = {
        taskId: '',
        procInstId: '',
        entityId: '',
        comment: '',
        passed: true
      }
      this.visable = false
    }
  }
}
</script>
